<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Access_library_sirak
{
	// Constructor
	public function __construct()
	{
		if (!isset($this->CI))
		{
			$this->CI =& get_instance();
		}
	}

	// Public methods
	public function is_logged_in()
	{

        session_start();
        if ($this->CI->session->userdata('sirakunp_user_username'))
		{
            if($this->CI->uri->segment(2) == 'login.html' || $this->CI->uri->segment(2) == 'login'){
              redirect('sirak', 'location');
		      exit();
            }
            else return;
        }
		else
		{
            if($this->CI->uri->segment(2) != 'login.html' && $this->CI->uri->segment(2) != 'login'){
              redirect('sirak/login/AuthWeb.do', 'location');
		      exit();
            }
		}
	}

    public function is_admin()
	{

        if ($this->CI->session->userdata('sirakunp_user_level') != 3)
		{
            show_404();
        }

	}

    public function renew_session_system()
    {
        /* unset session */
            $data = array(
                 'sirak_system_semester' => 0,
                 'sirak_system_tahun_ajaran' => 0,
                 'sirak_system_status' => 0
				 );

            //$this->CI->session->sess_destroy();
            $this->CI->session->unset_userdata($data);

            $viewKontrolData = $this->CI->system_model->getViewKontrolData($this->CI->session->userdata('sirakunp_user_kode_prodi'));

            /* set session */
            $sessionData = array(
                            'sirak_system_semester' => $viewKontrolData->KODE_SEMESTER,
                            'sirak_system_tahun_ajaran' => $viewKontrolData->KODE_TAHUN,
                            'sirak_system_status' => $viewKontrolData->KODE_STATUS
                            );
            $this->CI->session->set_userdata($sessionData);
    }
}

/* Developed by Eka Prakarsa */
/* Contact me at ekaprakarsa@facebook.com*/